package com.kayt.cyberBar.cuser.business.service.impl;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.ServerResponse;
import com.kayt.cyberBar.cuser.business.entity.po.BOrganizationStoreDepart;
import com.kayt.cyberBar.cuser.business.entity.po.BUser;
import com.kayt.cyberBar.cuser.business.entity.req.vo.StoreReqVO;
import com.kayt.cyberBar.cuser.business.entity.rsp.vo.DepartRspVO;
import com.kayt.cyberBar.cuser.business.entity.rsp.vo.UserDetailRspVO;
import com.kayt.cyberBar.cuser.business.server.IOrganizationStoreDepartServer;
import com.kayt.cyberBar.cuser.business.server.IStoreServer;
import com.kayt.cyberBar.cuser.business.service.IStoreService;

@Service("storeService")
public class StoreServiceImpl implements IStoreService {
	@Autowired
	private IStoreServer storeServer;
	@Autowired
	private IOrganizationStoreDepartServer organizationStoreDepartServer; 
	

	@Override
	public ServerResponse<PageData<DepartRspVO>> getDepartByStoreCode(StoreReqVO reqVO) throws SQLException {
		PageData<DepartRspVO> pageData = organizationStoreDepartServer.getOrganizationStoreDepartByStoreCode(reqVO.getPageNum(), reqVO.getPageSize(), reqVO.getStoreCode());
		return organizationStoreDepartServer.assembleResultPageData(pageData);
	}

	@Override
	public ServerResponse<PageData<UserDetailRspVO>> getUser(StoreReqVO reqVO) {
		PageData<BUser> pageResult = storeServer.getPageUserByStoreCode(reqVO);
		return storeServer.assemble_result(pageResult);
	}

	@Override
	public ServerResponse<String> addDepart(StoreReqVO reqVO) {
		BOrganizationStoreDepart organizationStoreDepart = storeServer.addDepart(reqVO.getStoreCode(),
				reqVO.getDepartCode(), reqVO.getStatusCode());
		return storeServer.assemble_result_String(organizationStoreDepart);
	}

	@Override
	public ServerResponse<String> deleteDepart(String id) {
		Integer result = storeServer.delete(id);
		return storeServer.assemble_result_Integer(result);
	}

	@Override
	public ServerResponse<String> updateDepart(StoreReqVO reqVO) {
		Integer result = storeServer.modifyDepart(reqVO.getId(), reqVO.getDepartCode(), reqVO.getStatusCode());
		return storeServer.assemble_result_Integer(result);
	}

	@Override
	public ServerResponse<PageData<UserDetailRspVO>> getUserByDepart(StoreReqVO reqVO) {
		PageData<BUser> pageData = storeServer.getBuserByStoreAndDepart(reqVO);
		return storeServer.assemble_result_user(pageData);
	}

}
